package com.example.myapplication.view.fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class TypeFragment extends Fragment {

    private ListView listview;
    private List<String> str;

    public TypeFragment() {
    }

    public static TypeFragment newInstance(String param1, String param2) {
        TypeFragment fragment = new TypeFragment();
        return fragment;
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_type, container, false);
        initView(v);
        setData(v);
        return v;
    }

    private void initView(View v) {
        listview = v.findViewById(R.id.refresh_lv);
    }

    private void setData(View v) {
        str = new ArrayList<String>();
        str.add("鸭药系列");
        str.add("鹅药系列");
        str.add("鸡药系列");
        str.add("猪药系列");
        str.add("牛羊药系列");
        listview.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return str.size();
            }

            @Override
            public Object getItem(int position) {
                return str.get(position);
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
               convertView= LayoutInflater.from(TypeFragment.this.getContext()).inflate(R.layout.type_adapter_layout,null);
                ViewGroup.LayoutParams lp=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,88);
                convertView.setLayoutParams(lp);
                TextView tv=convertView.findViewById(R.id.name);
                tv.setText(str.get(position));
                return convertView;
            }
        });
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    public interface OnFragmentInteractionListener {
        void onFragmentInteraction(Uri uri);
    }
}
